package com.connection.second.wallpaper.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.connection.second.wallpaper.domain.entity.PaperHomeBanner;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import com.connection.second.wallpaper.mapper.PaperWallMapper;
import com.connection.second.wallpaper.domain.entity.PaperWall;
import com.connection.second.wallpaper.service.IPaperWallService;

import javax.annotation.Resource;

/**
 * wallService业务层处理
 * 
 * @author ruoyi
 * @date 2024-11-12
 */
@Service
public class PaperWallServiceImpl implements IPaperWallService 
{
    @Resource
    private PaperWallMapper paperWallMapper;

    /**
     * 查询wall
     * 
     * @param id wall主键
     * @return wall
     */
    @Override
    public PaperWall selectPaperWallById(Long id)
    {
        return paperWallMapper.selectPaperWallById(id);
    }

    /**
     * 查询wall列表
     * 
     * @param paperWall wall
     * @return wall
     */
    @Override
    @Cacheable(value = "paperWallCache", key = "'selectPaperWallList'+#paperWall.toString()")
    public List<PaperWall> selectPaperWallList(PaperWall paperWall)
    {
        paperWall.setStatus("1");
        return paperWallMapper.selectPaperWallList(paperWall);
    }

    /**
     * 新增wall
     * 
     * @param paperWall wall
     * @return 结果
     */
    @Override
    public int insertPaperWall(PaperWall paperWall)
    {
        return paperWallMapper.insertPaperWall(paperWall);
    }

    /**
     * 修改wall
     * 
     * @param paperWall wall
     * @return 结果
     */
    @Override
    public int updatePaperWall(PaperWall paperWall)
    {
        return paperWallMapper.updatePaperWall(paperWall);
    }

    /**
     * 批量删除wall
     * 
     * @param ids 需要删除的wall主键
     * @return 结果
     */
    @Override
    public int deletePaperWallByIds(Long[] ids)
    {
        return paperWallMapper.deletePaperWallByIds(ids);
    }

    /**
     * 删除wall信息
     * 
     * @param id wall主键
     * @return 结果
     */
    @Override
    public int deletePaperWallById(Long id)
    {
        return paperWallMapper.deletePaperWallById(id);
    }

    @Override
    @Cacheable(value = "paperWallCache", key = "'randomWall'")
    public List<PaperWall> selectRandomWall() {
        List<PaperWall> list = paperWallMapper.selectPaperWallList(null);

        return list;
    }

    @Override
    public int updatePaperWallScore(Long id, String score) {
        PaperWall paperWall = new PaperWall();
        paperWall.setId(id);
        paperWall.setScore(score);
        return paperWallMapper.updatePaperWall(paperWall);
    }
}
